package com.lianbang.pharmacy.adapter

import android.widget.FrameLayout
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import cn.ubest.mvvmcore.utils.DialogUtils
import cn.ubest.mvvmcore.utils.ResourcesUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.entity.node.BaseNode
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lianbang.pharmacy.R
import com.lianbang.pharmacy.bean.ShopCarHeaderBean
import com.lianbang.pharmacy.bean.ShopCarItemBean

/**
 * Created by maoqi on 2020/12/13.
 */
class ShopCarListAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_shop_car_list) {

    override fun convert(helper: BaseViewHolder, item: String) {
        helper.setVisible(R.id.view_top, helper.layoutPosition == 0)
            .setText(R.id.tv_title, "湖北药丰大药房有限公司")
        val cvCard = helper.getView<CardView>(R.id.cv_card)
        if (helper.layoutPosition == 0) {
            (cvCard.layoutParams as FrameLayout.LayoutParams).topMargin =
                ResourcesUtils.getDimens(R.dimen.dp_20)
        } else {
            (cvCard.layoutParams as FrameLayout.LayoutParams).topMargin =
                ResourcesUtils.getDimens(R.dimen.dp_10)
        }
        helper.getView<RecyclerView>(R.id.rv_list).apply {
            layoutManager = LinearLayoutManager(context)
            adapter = ShopCarItemListAdapter().run {
                replaceData(mutableListOf("", "", ""))
                setOnItemLongClickListener { adapter: BaseQuickAdapter<*, *>, _, position ->
                    DialogUtils.showDialog(context, "确认删除该商品") { _, _ ->
                        adapter.remove(position)
                    }
                    true
                }
                this
            }
        }
    }

}